﻿using System.Collections;
using System.Collections.Generic;
using UnityEngine;

[RequireComponent(typeof(Rigidbody))]
public class Player : MonoBehaviour {

    public float mousePosZ = 10;
    public GameObject ball;

    Rigidbody rb;
    Camera mainCam;

	// Use this for initialization
	void Start () {
        rb = GetComponent<Rigidbody>();
        mainCam = Camera.main;
	}
	
	// Update is called once per frame
	void Update () {
        Vector3 mousePos = Input.mousePosition;
        Vector3 mousePosInWorld = mainCam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, mainCam.transform.position.y - transform.position.y));
        this.transform.LookAt(mousePosInWorld);

        //Vector3 mousePosNear = mainCam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, mainCam.nearClipPlane));
        //Vector3 mousePosFar = mainCam.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, mainCam.farClipPlane));

        //if (Input.GetMouseButton(0)) {
        //    if (Input.GetKeyDown(KeyCode.Space))
        //    {
        //        Instantiate(ball, mousePosInWorld, Quaternion.identity);
        //    }
        //    Debug.DrawRay(mousePosNear, mousePosInWorld - mousePosNear, Color.green);
        //    //Debug.DrawLine(mousePosNear, mousePosInWorld, Color.green);
        //}

	}
}
